﻿@{
    ViewBag.Title = "安克电子管理系统首页";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


@section Scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            if ($.cookie('easyuiThemeName')) {
                changeTheme($.cookie('easyuiThemeName'));
            }
            //加载树控件  获取菜单权限
            $("#menuTree").tree({
                url: "@Url.Content("~/Home/getMenuData")",
                onClick: function (node) {
                    if (node.attributes.url.length > 0)
                        newTab(node);
                },
                animate: true
            });
            $.setDivOnly("#divIndex");


            //add2021-05-10 plq 访问市120管理系统 start
            if ('@ViewBag.RoleFAPermissionInsert' == "Insert") {
                $(".city120").show();
            }
            else {
                $(".city120").hide();
            }

            $("#btnCity120").on("click", function () {
                var baseUrl = '@ViewBag.FAUrl';
                var workCode = '@ViewBag.WorkCode';
                window.open(baseUrl + "?WorkCode=" + workCode);
                //window.open(baseUrl + "?WorkCode=103019");
            });
            //add2021-05-10 plq 访问市120管理系统 end

            //add2021-09-10 sr 访问医保相关 start //add2021-10-18 plq 医保上线移植
            if ('@ViewBag.YBRole' == "Insert") {
                $(".ybrole").show();
            }
            else {
                $(".ybrole").hide();
            }

            $("#btnYB").on("click", function () {
                var baseUrl = '@Url.Content("~/BB/TJ/Page_YB")';
                window.open(baseUrl);
            });
        });
        $(window).resize(function () {
            $.setDivOnly("#divIndex");
        });
        //追加一个新的 Tab
        function newTab(treeNode) {
            var $tbs = $("#tbs");//获取tab容器
            //新根据 标题 判断 是否以存在 同名tab
            if ($tbs.tabs("exists", treeNode.text)) {
                //判断正在看的选项卡,是否和点击的树节点相同
                //获取 当前选项卡
                var currTab = $tbs.tabs('getSelected');
                //获取当前选项卡的标题
                var currTitle = currTab.panel('options').title
                //拿当前标题 和 被点击的 树节点标题比较，如果相等，则要刷新
                if (currTitle == treeNode.text) {
                    $tbs.tabs('update', {
                        tab: currTab,//要更新的标签
                        options: {//设置更新标签要修改的属性
                            content: newIframe(treeNode.attributes.url)//重新加载iframe
                        }
                    });
                }

                $tbs.tabs("select", treeNode.text);
            } else {
                $tbs.tabs("add", {
                    title: treeNode.text,
                    iconCls: treeNode.iconCls,
                    content: newIframe(treeNode.attributes.url),
                    closable: true,
                    fit: true
                });
            }
        }
        //返回一个<iframe></iframe>标签  撑满子页面
        function newIframe(url) {
            url = '@Url.Content("~/")' + url;
            var ifrStr = "<iframe src='" + url + "' style='width:99.5%;height:99%;border:0px solid #000;'></iframe>";
            return ifrStr;
        }
        function goLogin() {
            @*window.top.location.href = '@ViewBag.urllogin';*@
            $.messager.confirm('关闭业务系统', '是否确定要关闭业务系统？"', function (r) {
                if (r) {
                    @*window.opener = null;
                    window.open('', '_self', '');
                    window.close();
                    $.ajax({
                        type: 'POST',
                        url: '@Url.Content("~/Home/StateLog")',
                        data:
                            {
                                Description: "退出",
                                LoginName: '@ViewBag.LoginNameNew'
                            },
                        dataType: "json",
                        success: function (msg) {
                            if (msg == "1") {
                            }
                        }
                    })*@

                    //add2021-06-08 plq 退出登录重写
                    $.ajax({
                        type: 'POST',
                        url: '@Url.Content("~/Home/ExitLogin")',
                        data:
                            {
                                LoginName: '@ViewBag.LoginNameNew'
                            },
                        dataType: "json",
                        success: function (msg) {
                            //console.log(msg);
                            if (msg == "OK") { //记录退出登录状态日志成功

                                //使用window.opener的时候要去判断父窗口的状态，否则若父窗口被关闭或者更新，就会出错
                                if (window.opener && !window.opener.closed) {
                                    window.opener.opener = null;
                                    window.opener.open("", "_self");
                                    window.opener.close(); //关闭源（父）窗口
                                }

                                //返回用户登录页
                                window.top.location.href = '@Url.Content("~/Home/UserLogin")';
                            }
                        }
                    });
                }
            });
        }
        function changeTheme(i) {
            $("#comboTheme").combobox('select', i);
            switch (i) {
                case 'default':
                    changeThemeFun("default");
                    $("#divIndexTop").css("background-color", "#E4F2FB");
                    $("#divIndexMain").css("background-color", "#E4F2FB");
                    break;
                case 'gray':
                    changeThemeFun("gray");
                    $("#divIndexTop").css("background-color", "#F3F3F3");
                    $("#divIndexMain").css("background-color", "#F3F3F3");
                    break;
                case 'kitty':
                    changeThemeFun("kitty");
                    $("#divIndexTop").css("background-color", "#F4CCDA");
                    $("#divIndexMain").css("background-color", "#F4CCDA");
                    break;
                case 'black':
                    changeThemeFun("black");
                    $("#divIndexTop").css("background-color", "#666666");
                    $("#divIndexMain").css("background-color", "#666666");
                    break;
                case 'metro':
                    changeThemeFun("metro");
                    $("#divIndexTop").css("background-color", "#FFFFFF");
                    $("#divIndexMain").css("background-color", "#FFFFFF");
                    break;
                default:

            }
        };
        //关闭修改密码弹出框
        function Close() {
            $("#update").dialog('close');
        }
        $(function () {
            Close();
            //$("#NewPwd").textbox('textbox').bind('keyup', function () {
            //    ValidateValue(this);
            //});
            //$("#SurePwd").textbox('textbox').bind('keyup', function () {
            //    ValidateValue(this);
            //});
        });
        //点击修改密码按钮。打开弹出框
        $("#updatePwd").click(function () {
            $("#update").dialog('open');
            $("#NewPwd").val(null);
            $("#SurePwd").val(null);
        });
        //验证修改密码输入是否一致
        $.extend($.fn.validatebox.defaults.rules, {
            /*必须和某个字段相等*/
            equalTo: {
                validator: function (value, param) {
                    return $(param[0]).val() == value;
                },
                message: '字段不匹配'
            }

        });
        //修改密码后保存
        $("#btnSavePwd").click(function () {
            //var IdCard = $("#IdCard").val();
            var NewPwd = $("#NewPwd").val();
            var SurePwd = $("#SurePwd").val();
            if (NewPwd == SurePwd) {
                $.post('@Url.Content("~/Home/UpdatePwd")', { NewPwd: NewPwd}, function (data) {
                    if (data == "OK") {
                        alert("修改成功！");
                        Close();
                        //window.location.href = "/Home/UserLogin";
                        window.location.href = '@Url.Content("~/Home/UserLogin")'; //返回登录页 add20200511 plq
                    } else {
                        alert("修改失败！");
                        Close();
                    }
                })
            } else {
                alert("两次密码输入不一致");
                $("#NewPwd").val(null);
                $("#SurePwd").val(null);
            }
        });
        //禁止输入特殊字符串
        function ValidateValue(textbox) {
            var IllegalString = "[`~!#$^&*()=|{}':;',\\[\\].<>/?~！#￥……&*（）——|{}【】‘；：”“'。，、？]‘' -_+";
            var textboxvalue = textbox.value;
            var index = textboxvalue.length - 1;
            var s = textbox.value.charAt(index);
            if (IllegalString.indexOf(s) >= 0) {
                s = textboxvalue.substring(0, index);
                textbox.value = s;
                $.messager.alert('提示', '不允许输入特殊字符', function () {
                });
            }
        }
    </script>
}
<div id="divIndex" class="easyui-layout" style="width:auto; height: auto; margin-left: auto; margin-right: auto">
    <div id="divIndexTop" data-options="region:'north',split:false" style="height: 55px; background-color: #E4F2FB; overflow: hidden; ">
        <img src="~/Images/Top/logo.png" />
        <div style="position: absolute; right: 0px; bottom: 0px; width: 150px; height: 30px; vertical-align:auto">
            @*主题：<select id="comboTheme" class="easyui-combobox" name="dept" style="width:100px;" data-options="onSelect: function(rec){
          changeTheme(rec.value);
            },editable:false">
                <option value="default">default</option>
                <option value="gray">gray</option>
                <option value="black">black</option>
                <option value="metro">metro</option>
                <option value="kitty">kitty</option>
            </select>*@
        </div>
        <div style="position: absolute; right: 480px; bottom: 8px; width: 80px; height: 25px; vertical-align:auto" class="ybrole">
            <a href="javascript:void(0)" id="btnYB" class="easyui-linkbutton">医保管理</a>
        </div>
        <div style="position: absolute; right: 330px; bottom: 8px; width: 80px; height: 25px; vertical-align:auto" class="city120">
            <a href="javascript:void(0)" id="btnCity120" class="easyui-linkbutton">市120管理</a>
        </div>
        <div style="position: absolute; right: 150px; bottom: 3px; width: 180px; height: 25px; vertical-align:auto">
            当前登录人：<span style="color:darkblue">@ViewBag.LoginName</span>&nbsp;&nbsp;
        </div>
        <div style="position: absolute; right: 50px; bottom: 8px; width: 100px; height: 25px; vertical-align:auto">
            <a href="javascript:void(0)" id="updatePwd" class="easyui-linkbutton" style="color: red;">修改密码</a>
        </div>
        <div id="update" class="easyui-dialog" title="修改密码" data-options="iconCls:'icon-save'" style="width:400px;height:240px;padding:10px">
            <div data-options="region:'center'" style="overflow: hidden">
                <table style="width:99%">
                    <tr style="height:40px">
                        <td>&nbsp;&nbsp;当前工号：</td>
                        <td>
                            <input type="text" id="IdCard" style="width:160px" data-options="required:true" value="@ViewBag.LoginNameNew" readonly="readonly" />
                        </td>
                    </tr>
                    <tr style="height:40px">
                        <td>&nbsp;&nbsp;新密码：</td>
                        <td>
                            <input type="password" id="NewPwd" class="easyui-validatebox" style="width:160px" data-options="required:true" onkeyup="ValidateValue(this)" />
                        </td>
                    </tr>
                    <tr style="height:40px">
                        <td>&nbsp;&nbsp;确认密码：</td>
                        <td>
                            <input type="password" id="SurePwd" class="easyui-validatebox" style="width:160px" data-options="required:true"
                                   validtype="equalTo['#NewPwd']" invalidmessage="两次输入密码不匹配" onkeyup="ValidateValue(this)" />
                        </td>
                    </tr>
                    <tr style="height:30px">
                        <td colspan="2" align="center">
                            <a href="javascript:void(0)" id="btnSavePwd" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">保存</a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div style="position: absolute; right: 60px; bottom: 6px; width: 20px; height: 20px; vertical-align:auto">
            <img src="~/Images/Top/outLogin.png" style="height:16px; width:16px; cursor:pointer" onclick="goLogin()" />
        </div>
    </div>
    <div data-options="region:'west',title:'菜单导航',split:false" style="width:180px;height:30px;">
        <ul id="menuTree"></ul>
    </div>
    <div id="divIndexMain" data-options="region:'center'" style="padding: 5px; background: #E4F2FB;">
        <div id="tbs" class="easyui-tabs" data-options="fit:true,border:false">
            <div title="安克OA" data-options="iconCls:'icon-custom-Anke'" style="padding:10px">
                <iframe src='~/Home/Home' style='width:99.5%;height:99%;border:0px solid #000;'></iframe>
            </div>
        </div>
    </div>
</div>
